package com.sezi.blog.entity;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/***
 * 权限实体类
 * @author yuanyi
 * @Date 2015-4-16
 * @version 1.0
 */
@Entity
@Table(name="b_permission")
public class Permission {
	
	/**id*/
	private Long id;
	/**权限名称*/
	private String name;
	/**权限值*/
	private Integer value;
	/**是否启用*/
	private boolean started;
	/**拥有此权限的角色*/
	private List<Role> roles;
	/**单独拥有此权限的用户*/
	private List<User> users;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Integer getValue() {
		return value;
	}
	
	public void setValue(Integer value) {
		this.value = value;
	}
	
	public boolean isStarted() {
		return started;
	}
	
	public void setStarted(boolean started) {
		this.started = started;
	}
	
	@ManyToMany(mappedBy="permissions")
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	@ManyToMany
	@JoinTable(name="user_permission",
	joinColumns={@JoinColumn(name="permission_id",referencedColumnName="id")},
	inverseJoinColumns={@JoinColumn(name="user_id",referencedColumnName="id")})
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
}
